//
//  MyShipmentAddressCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/26.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "MyShipmentAddressCell.h"

@interface MyShipmentAddressCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *faImgView;
@property (nonatomic, strong) UILabel *faNameLab;
@property (nonatomic, strong) UILabel *faAddressLab;
@property (nonatomic, strong) UILabel *faCompanyLab;
@property (nonatomic, strong) UILabel *marginLine;
@property (nonatomic, strong) UIImageView *shouImgView;
@property (nonatomic, strong) UILabel *shouNameLab;
@property (nonatomic, strong) UILabel *shouAddressLab;
@property (nonatomic, strong) UILabel *shouCompanyLab;
@property (nonatomic, strong) UILabel *linkLine;

@end

@implementation MyShipmentAddressCell

+ (instancetype)MyShipmentAddressCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"MyShipmentAddressCell";
    MyShipmentAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MyShipmentAddressCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.faImgView = [UIImageView new];
        self.faImgView.image = [UIImage imageNamed:@"icon_add_fa"];
        [self.bgView addSubview:self.faImgView];
        
        self.faNameLab = [UILabel new];
        self.faNameLab.textColor = HexColor(0x2B2C44);
        self.faNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.faNameLab];
        
        self.faAddressLab = [UILabel new];
        self.faAddressLab.textColor = HexColor(0x9C9DB3);
        self.faAddressLab.font = [UIFont systemFontOfSize:14];
        self.faAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.faAddressLab];
        
        self.faCompanyLab = [UILabel new];
        self.faCompanyLab.textColor = HexColor(0x9C9DB3);
        self.faCompanyLab.font = [UIFont systemFontOfSize:14];
        self.faCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.faCompanyLab];
        
        self.shouImgView = [UIImageView new];
        self.shouImgView.image = [UIImage imageNamed:@"icon_add_shou"];
        [self.bgView addSubview:self.shouImgView];
        
        self.shouNameLab = [UILabel new];
        self.shouNameLab.textColor = HexColor(0x2B2C44);
        self.shouNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.shouNameLab];
        
        self.shouAddressLab = [UILabel new];
        self.shouAddressLab.textColor = HexColor(0x9C9DB3);
        self.shouAddressLab.font = [UIFont systemFontOfSize:14];
        self.shouAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouAddressLab];
        
        self.shouCompanyLab = [UILabel new];
        self.shouCompanyLab.textColor = HexColor(0x9C9DB3);
        self.shouCompanyLab.font = [UIFont systemFontOfSize:14];
        self.shouCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouCompanyLab];
        
        self.marginLine = [UILabel new];
        self.marginLine.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
    }
    return self;
}

-(void)setModel:(WaybillMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.faNameLab.text = self.model.send_name;
    [self.faNameLab sizeToFit];
    self.faNameLab.nim_left = 59;
    self.faNameLab.nim_top = 15;
    self.faNameLab.nim_width = self.bgView.nim_width - 70 - 10 - self.faNameLab.nim_left;
    
    self.faAddressLab.nim_width = self.faNameLab.nim_width;
    self.faAddressLab.text = self.model.send_address.addrs;
    self.faAddressLab.nim_left = self.faNameLab.nim_left;
    self.faAddressLab.nim_top = self.faNameLab.nim_bottom + 10;
    [self.faAddressLab sizeToFit];
    self.faAddressLab.nim_width = self.faNameLab.nim_width;
    
    self.faCompanyLab.nim_width = self.faAddressLab.nim_width;
    self.faCompanyLab.text = [NSString stringWithFormat:@"%@ %@",self.model.send_address.tel_name,self.model.send_address.phone];
    self.faCompanyLab.nim_left = self.faAddressLab.nim_left;
    self.faCompanyLab.nim_top = self.faAddressLab.nim_bottom + 5;
    [self.faCompanyLab sizeToFit];
    self.faCompanyLab.nim_width = self.faAddressLab.nim_width;
    
    self.marginLine.frame = CGRectMake(52, 10 + self.faCompanyLab.nim_bottom, self.bgView.nim_width - 52, 1);

    self.shouNameLab.text = self.model.shipper_name;
    [self.shouNameLab sizeToFit];
    self.shouNameLab.nim_left = 59;
    self.shouNameLab.nim_top = 10 + self.marginLine.nim_bottom;
    self.shouNameLab.nim_width = self.bgView.nim_width - 70 - 10 - self.shouNameLab.nim_left;
    
    self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
    self.shouAddressLab.text = self.model.saddress.addrs;
    self.shouAddressLab.nim_left = self.shouNameLab.nim_left;
    self.shouAddressLab.nim_top = self.shouNameLab.nim_bottom + 10;
    [self.shouAddressLab sizeToFit];
    self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
    
    self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
    self.shouCompanyLab.text = [NSString stringWithFormat:@"%@ %@",self.model.saddress.tel_name,self.model.saddress.phone];
    self.shouCompanyLab.nim_left = self.shouAddressLab.nim_left;
    self.shouCompanyLab.nim_top = self.shouAddressLab.nim_bottom + 5;
    [self.shouCompanyLab sizeToFit];
    self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
    
    self.faImgView.nim_width = 22;
    self.faImgView.nim_height = 22;
    self.faImgView.nim_left = 20;
    self.faImgView.nim_top = (self.marginLine.nim_top - self.faImgView.nim_width) * 0.5;
    
    self.shouImgView.nim_width = 22;
    self.shouImgView.nim_height = 22;
    self.shouImgView.nim_left = 20;
    self.shouImgView.nim_top = (self.shouCompanyLab.nim_bottom + 15 - self.marginLine.nim_bottom - self.shouImgView.nim_height) * 0.5 + self.marginLine.nim_bottom;
    
    self.linkLine.nim_width = 2;
    self.linkLine.nim_top = self.faImgView.nim_bottom + 3;
    self.linkLine.nim_height = self.shouImgView.nim_top - 3 - self.linkLine.nim_top;
    self.linkLine.nim_centerX = self.faImgView.nim_centerX;
    
    self.bgView.nim_height = self.shouCompanyLab.nim_bottom + 15;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
